#ifndef structures_h
#define structures_h

/************************************************************************************************* 
	
	Name: structures.h
	Autor: JA&AP
	contenido: este archivo contiene las estructuras de datos utilizadas 

**************************************************************************************************/
//#include "nxbot.h"


#define MAX_SONAR_COUNT 8

//! Data structure associated with robot velocities
typedef struct{
	/** Right actual velocity */
	int velRightAct;
	/** Left actual velocity */
	int velLeftAct;
	/** Right reference velocity */
	int velRightRef;
	/** Left reference velocity */
	int velLeftRef;
}velocities_t;

//! Data structure associated with robot odometers
typedef struct{
	/** Left actual encoder count */
	long posLeft;
	/** Right actual encoder count */
	long posRight;
	/** Left previous encoder count */
	long lastPosLeft;
	/** Right previous encoder count */
	long lastPosRight;
	
}encoders_t;

//! Data structure associated with robot motors
typedef struct{
	/** Odometers */
	encoders_t encoders;
	/** Velocities */
	velocities_t velocities;
}motors_t;

//! Data structure associated with robot battery state
typedef struct{
	/** Battery state [%] */
	unsigned char battState;
	/** Battery voltage [V] */
	unsigned int battVoltage;
}battery_t;

//! Data structure associated with robot sensors
typedef struct{
	/** IR sensors */
	unsigned char sensorsIR;
	/** Bumper sensors */
	unsigned char bumpers;
	/** Sonar sensors */
	unsigned int sonars[MAX_SONAR_COUNT];
	/** Battery state */
	battery_t batt;
}sensors_t;

/* 	Estructura estado TODO: yaw es copia de orientation, hay que ver como corregir!
	
*/
//! Data structure associated with robot pose
typedef struct{
	/** x position [m]*/
	float x;
	/** y position [m]*/
	float y;
	/** orientation [rad] */
	float orientation;
	/** a copy of orientation*/
	float yaw;
	
}robotPose_t;


//! Data structure associated with task frequencies
typedef struct{
	/** Frequency for commTask*/
	unsigned int intervalComm;
	/** Frequency for motorsTask*/
	unsigned int intervalMotors;
	/** Frequency for sensorsTask*/
	unsigned int intervalSensors;
	/** Frequency for sonarsTask*/
	unsigned int intervalSonars;
}times_t;

typedef struct{
	float Kp;
	float Ki;
	int Kp_int;
	int Ki_int;
	int right_acumm_error;
	int left_acumm_error;
}parametersPI_t;

//! Data structure describing the robot geometry.
		//TODO: Utilizar esta estructura para la calibracion de la odometria	

typedef struct{
	float radiusWheel;
	float radialDist;
	float encResolution;
}robotGeometry_t;



//! Data structure containing all information.

 //Used for easy communication of information between tasks.
 
typedef struct{
	//velocities_t velocities;
	//encoders_t encoders;
	motors_t motors;
	sensors_t sensors;
	robotPose_t robotPose;
	times_t times;
	parametersPI_t parametersPI;
	robotGeometry_t robotGeometry;
	int soundJingle;
}globals_t;




#endif
